﻿<UserControl x:Class="Ops.Mpc.ExampleApplication.DataTemplateBindings.DataTemplateBindingsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:presenters="clr-namespace:Ops.Mpc.Presenters;assembly=Ops.Mpc"
    xmlns:controllers="clr-namespace:Ops.Mpc.Controllers;assembly=Ops.Mpc"   
    xmlns:states="clr-namespace:Ops.Mpc.States;assembly=Ops.Mpc"   
    xmlns:datatemplatemodels="clr-namespace:Ops.Mpc.ExampleApplication.DataTemplateBindings.Models" 
    xmlns:datatemplateactions="clr-namespace:Ops.Mpc.ExampleApplication.DataTemplateBindings.Actions"
    xmlns:interactions="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  
    xmlns:actions="clr-namespace:Ops.Mpc.ExampleApplication.Actions"       
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <presenters:Presenter x:Name="Presenter1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
        <controllers:Controller>
            <controllers:Controller.Models>
                <datatemplatemodels:DataTemplateModel ItemName="DataTemplateModel" />
            </controllers:Controller.Models>
            <controllers:Controller.States>
                <states:State ItemName="DefaultState" AutoRun="True">
                    <states:StateTemplate>
                        <Grid>
                            <Grid HorizontalAlignment="Center" VerticalAlignment="Center"  >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="10"/>
                                    <RowDefinition Height="40" />
                                </Grid.RowDefinitions>
                                <ItemsControl Grid.Row="0" ItemsSource="{Binding Models[DataTemplateModel].Persons}" HorizontalAlignment="Center" >
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <HyperlinkButton Content="{Binding LastNameFirstName}" Command="{Binding StateActions[SelectedPersonChangedStateAction], Source={StaticResource Resolver}}" CommandParameter="{Binding}" IsEnabled="{Binding StateActions[SelectedPersonChangedStateAction].IsAvailable}"/>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <TextBlock Grid.Row="2" Text="{Binding Models[DataTemplateModel].SelectedPerson.LastNameFirstName, Mode=OneWay, StringFormat='Selected {0}'}" Margin="5" HorizontalAlignment="Center" />
                             </Grid>
                        </Grid>
                    </states:StateTemplate>
                    <states:State.StateActions>
                        <states:CompositeStateAction ItemName="CompositeStateAction" BusyIndicatorModelItemName="BusyIndicatorModel">
                            <actions:SetMainMessageStateAction ItemName="SetMainMessageStateAction" MessageId="DataTemplateMessage" BusyIndicatorModelItemName="BusyIndicatorModel"/>
                            <datatemplateactions:GetPersonsStateAction ItemName="GetPersonsStateAction" BusyIndicatorModelItemName="BusyIndicatorModel" />
                        </states:CompositeStateAction>
                        <datatemplateactions:SelectedPersonChangedStateAction ItemName="SelectedPersonChangedStateAction" />
                    </states:State.StateActions>
                </states:State>
            </controllers:Controller.States>
        </controllers:Controller>
    </presenters:Presenter>
</UserControl>
